package com.ljy.my_study.java.thread;

/**
 * @author lijunying
 * @date 2021/2/22 17:14
 */
public class ThreadLocalTestMain {

    public static void main(String[] args) {
        Student a=new Student("James",27);
        StudentPlayGame thread=new StudentPlayGame();
        thread.setName("StudentPlayGame thread");
        thread.start();
        System.out.println(Thread.currentThread().getName()+":"+Student.threadLocal.get());
    }

    public static class StudentPlayGame extends Thread{

        @Override
        public void run() {
            super.run();
            System.out.println(Thread.currentThread().getName()+":"+Student.threadLocal.get());
        }
    }

    public static class Student{

        static ThreadLocal threadLocal=new ThreadLocal();

        public Student(String name, int age) {
            this.name = name;
            this.age = age;
            threadLocal.set(name);
        }

        String name;
        int age;

        @Override
        public String toString() {
            return "Student{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }
}
